﻿using System.Diagnostics;

namespace MikadoShooter
{
    public class Fps
    {
        private readonly Stopwatch fps;
        private uint fpsCount;
        private uint fpsFinal;

        public Fps()
        {
            fps = new Stopwatch();
        }

        public bool Update()
        {
            if (!fps.IsRunning)
            {
                fpsCount = 0;
                fps.Start();
            }

            if (fps.ElapsedMilliseconds >= 1000)    // frames per secound
            {
                fpsFinal = fpsCount;
                fpsCount = 0;
                fps.Restart();

                return true;
            }

            fpsCount++;
            return false;
        }

        public uint Draw()
        {
            return fpsFinal;
        }
    }
}